<template>
	<view class="login" style="background: url('../../static/image/background1.png') no-repeat center;
  height: 100%;
  
  display: flex;
  flex-direction: column;
  align-items: center;">
		<view class="logo" style="background: url('../../static/image/logo.png') no-repeat center;
	background-size: 100%;
	width: 384rpx;
	height: 384rpx;
	margin-top: 136rpx;
	margin-bottom: 60rpx;"></view>
		<view class="logobox" style=" background: url('../../static/image/logobox.png') no-repeat center;
	background-size: 100%;
	width: 348px;
	height: 286px;
	
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;">
			<view class="username">
				<view class="icon_username"></view>
				<input class="uni-input" type="text" placeholder="请输入用户名" v-model="account" />
			</view>
			<view class="password">
				<view class="icon_password"></view>
				<input class="uni-input" :type="isPassword" placeholder="请输入密码" v-model="password" style="border:none;width:80%;" />
				<!-- <input placeholder="请输入密码" v-model="password" type="text" show-password class="uni-input" /> -->
				<view class="onshow" @click="showPWD"></view>
			</view>
			<button class="logining" type="primary" @click="Login">登录</button>
		</view>
	</view>
</template>

<script>
	import "../../api/apis";
	import {
		ajax,
		ApiUrl
	} from "../../api/apis";
	import store from "../../store/store";
	import CryptoJS from "crypto-js";
	export default {
		data() {
			return {
				isPassword: "password",
				account: "admin",
				password: "123456",
				userid: ""
			};
		},
		onLoad() {},
		methods: {
			Login() {
				var account = this.encrypt(this.account)
				var password = this.encrypt(this.password);
				console.log(account,password)
				var _this = this;
				ajax({
					url: "/user/login",
					method: "POST",
					data: {
						account,
						password
					},
					success: res => {
						// console.log(res.data.data.roleSimpleOutputDTOList)
						let _this = this;
						let id = res.data.data.userID;
						let roleid = res.data.data.roleSimpleOutputDTOList[0].roleID
						// console.log(roleid)
						uni.setStorageSync("userid", id);
						uni.setStorageSync("jzg_token", res.data.data.token);
						let user = {
							account,
							password,
							roleid
						}
						uni.setStorageSync("user", user)
						ajax({
							url: "/messageSubscribe/updateDeviceId",
							method: "POST",
							data: {
								userId: id,
								deviceId: uni.getStorageSync("deviceId")
							},
							success: function() {
								uni.switchTab({
									url: "../monitor/monitor"
								});
							}
						});
					}
				});
			},
			showPWD() {
				this.isPassword = this.isPassword === "password" ? "text" : "password";
			},
			encrypt(plaintText) {
				var options = {
					mode: CryptoJS.mode.ECB,
					padding: CryptoJS.pad.Pkcs7
				};
				var key = CryptoJS.enc.Utf8.parse('abcdefgabcdefg12');
				var encryptedData = CryptoJS.AES.encrypt(plaintText, key, options);
				var encryptedBase64Str = encryptedData.toString();
				return encryptedBase64Str;
			}
		}
	};
</script>

<style scoped>
	uni-page-body {
		height: 100%;
	}

	.uni-input {
		width: 272px;
		text-indent: 15px;
	}

	.uni-input>>>.uni-input-placeholder {
		font-size: 14px;
		color: #ccc;
	}

	.username,
	.password {
		display: flex;
		width: 272px;
		margin: 16px 39px;
		padding-bottom: 16px;
		border-bottom: 1px solid #ccc;
		align-items: center;
	}

	.icon_username {
		background: url("../../static/image/icon_username.png") no-repeat center;
		background-size: contain;
		width: 15px;
		height: 22px;
	}

	.icon_password {
		background: url("../../static/image/icon_password.png") no-repeat center;
		background-size: contain;
		width: 15px;
		height: 22px;
	}

	.onshow {
		background: url("../../static/image/Show.png") no-repeat center;
		background-size: contain;
		width: 20px;
		height: 12px;
		position: relative;
		right: 0;
	}

	.logining {
		font-size: 16px;
		padding: 5px 100px;
		background-color: #009ff1;
		cursor: pointer;
	}
</style>
